const path = require('path');
const DLLPlugin = require('webpack/lib/DllPlugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = function(name, config) {
    const baseDir = path.resolve(__dirname, '../../'),  // 根目录
        dllDir = path.resolve(baseDir, 'dll', `${name}_dll`),
        devDir = path.resolve(baseDir, 'dll', `${name}_dll_dev`);

    function buildConfig( dev ) {
        const dir = dev ? devDir: dllDir;
        return {
            mode: dev? 'development': 'production',
            entry: {
                [ name ]: config.libs
            },
            output: {
                filename: '[name].dll.js',
                path: dir,
                library: '_dll_[name]',
            },
            plugins: [
                new CleanWebpackPlugin(),
                new DLLPlugin({
                    name: '_dll_[name]',
                    path: path.join(dir, `[name].manifest.json`),
                    context: dir
                })
            ]
        }
    }

    return [
        buildConfig(true),
        buildConfig(false)
    ]
}